import 'package:flutter/material.dart';
import 'dart:async';
import 'login.dart';
import 'userModelSingleton.dart';

class LoadingPage extends StatefulWidget {
  @override
  _LoadingState createState() => new _LoadingState();
}
class _LoadingState extends State<LoadingPage> {
  @override
  void initState(){
    super.initState();
    _checkLoginStatus();
  }
  Future<void> _checkLoginStatus() async {
    await UserModelSingleton().loadUserModel();
    if (UserModelSingleton().isLoggedIn()) {
      Navigator.pushReplacementNamed(context, "app");
    } else {
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(builder: (context) => LoginPage()),
      );
    }
  }
  @override
  Widget build(BuildContext context) {
    return new Container(
      child: Image.asset("images/loading.jpg"),
    );
  }
}